﻿using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using MyWeb.Common.MemoryCache;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWeb.Extensions.ServiceExtensions.RedisCache
{
    /// <summary>
    /// Memory缓存 启动服务
    /// </summary>
    public static class MemoryCacheSetup
    {
        /// <summary>
        /// MemoryCache缓存 启动服务
        /// </summary>
        /// <param name="services"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void AddMemoryCacheSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));

            services.AddScoped<ICaching, MemoryCaching>();
            services.AddMemoryCache(); //或者
            //services.AddSingleton<IMemoryCache>(factory =>
            //{
            //    var value = factory.GetRequiredService<IOptions<MemoryCacheOptions>>();
            //    var cache = new MemoryCache(value);
            //    return cache;
            //});
        }
    }
}
